import { Modal, Empty } from "antd";
import "./index.scss";

const File = ({ previewInfo }) => {
  if (previewInfo.title?.includes("图片")) {
    return (
      <div className="preview-file">
        <img src={previewInfo.url} />
      </div>
    );
  } else if (previewInfo.title?.includes("视频")) {
    return (
      <div className="preview-file">
        <video src={previewInfo.url} controls />
      </div>
    );
  } else if (previewInfo.title?.includes("音乐")) {
    return (
      <div className="preview-file">
        <audio src={previewInfo.url} controls />
      </div>
    );
  } else if (previewInfo.title?.includes("文档")) {
    if (previewInfo.file?.fileType === "pdf") {
      return (
        <iframe className="preview-iframe" src={previewInfo?.url}></iframe>
      );
    } else {
      return (
        <Empty
          image="https://xwjblog.cn/pan/hehe/hehe-shidizai2-1669021271430"
          imageStyle={{
            height: 180,
          }}
          description={<span>文档暂时只支持pdf预览 ！！！</span>}
        ></Empty>
      );
    }
  } else {
    return (
      <Empty
        image="https://xwjblog.cn/pan/hehe/hehe-shidizai2-1669021271430"
        imageStyle={{
          height: 180,
        }}
        description={<span>这种文件你也想看！！！</span>}
      ></Empty>
    );
  }
};
const PreviewFile = (props) => {
  const handleCancel = () => {
    props.onCancel();
  };
  return (
    <div>
      <Modal
        className="preview-modal"
        title={props.previewInfo?.title}
        open={props.visible}
        onCancel={handleCancel}
        footer={null}
      >
        <File previewInfo={props.previewInfo}></File>
      </Modal>
    </div>
  );
};
export default PreviewFile;
